package com.neko.Thread_Learning;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 回顾 & 总结
 *  线程的创建
 * */
public class t22_Summary_Thread {
    public static void main(String[] args) {

        // 1、extends Thread 调用方式
        new MyThread1().start();

        // 2、implements Runnable 调用方式
        new Thread(new MyThread2()).start();

        // 3、implements Callable<T> 方式2
        FutureTask<Integer> futureTask = new FutureTask<Integer>(new MyThread3());
        new Thread(futureTask).start();

        try {
            Integer integer = futureTask.get();

            System.out.println(integer);

        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }

}

// 1、extends Thread
class MyThread1 extends Thread {
    @Override
    public void run() {
        System.out.println("MyThread 1");
    }
}

// 2、implements Runnable
class MyThread2 implements Runnable {
    @Override
    public void run() {
        System.out.println("MyThread 2");
    }
}

// 3、implements Callable<T>
class MyThread3 implements Callable<Integer> {
    @Override
    public Integer call() throws Exception {
        System.out.println("MyThread 3");
        return 100;
    }
}